﻿using System;
using System.Windows.Forms;
using DevExpress.XtraBars;
using DevExpress.LookAndFeel;
using System.Data;
using System.Data.SqlClient;
using DevExpress.Skins;
using DevExpress.XtraBars.Helpers;

namespace HMS
{
    public partial class FRM_Manhinhchinh : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        public static string sConn = @"Data Source=.\SQLEXPRESS;Initial Catalog=HMSTeam22;User ID=sa;Password=123456";
        private SqlConnection con = new SqlConnection(sConn);
        private SqlDataAdapter dataAp;
        private DataTable dataTable;
        private bool bClosed;

        public FRM_Manhinhchinh()
        {
            InitializeComponent();
            skinschange();
            UserLookAndFeel.Default.SetSkinStyle("Office 2010 Blue");
        }

        public DataTable GetDataTable(string sql)
        {
            // Tạo dataApdapter, thực hiện câu lệnh query
            dataAp = new SqlDataAdapter(sql, con);
            // Đổ dữ liệu vào DataTable
            dataTable = new DataTable();
            dataAp.Fill(dataTable);
            return dataTable;
        }// end GetDataTable

        public void EnableMenu(string userid)
        {
            GetDataTable(String.Format("select distinct a.authorization_id from tblauthorization a, tbluser u where a.userid = '{0}'", userid));
            foreach (DataRow row in dataTable.Rows)
            {
                switch(row["authorization_id"].ToString()){
                    case "1":
                        rbpQuantrihethong.Visible = true;
                        break;
                    case "2":
                        rbpQuanlibenhnhan.Visible = true;
                        break;
                    case "3":
                        rbpDanhmuchethong.Visible = true;
                        break;
                    case "4":
                        rbpBaocaothongke.Visible = true;
                        break;
                }// end switch
            }// end foreach
            bstiUser.Caption = String.Format("{0} - {1}", FRM_Dangnhap.userid, FRM_Dangnhap.name);
        }// end EnableMenu

        void skinschange()
        {
            DevExpress.UserSkins.BonusSkins.Register();
            SkinHelper.InitSkinPopupMenu(bsSkin);
            
        }// end skinschange

        //them giao dien dia diem
        private void btnDiadiem_ItemClick(object sender, ItemClickEventArgs e)
        {
            panelControl1.Controls.Clear();
            ucQuanhuyen frm = new ucQuanhuyen();
            frm.Dock = System.Windows.Forms.DockStyle.Fill;
            panelControl1.Controls.Add(frm);
        }

        //quay ve man hinh chinh
        private void bbtnManhinhchinh_ItemClick(object sender, ItemClickEventArgs e)
        {
            panelControl1.Controls.Clear();
            ucManhinhchinh frm = new ucManhinhchinh();
            frm.Dock = System.Windows.Forms.DockStyle.Fill;
            panelControl1.Controls.Add(frm);
        }// end bbtnManhinhchinh_ItemClick

        //them giao dien phong kham
        private void btnPhongkham_ItemClick(object sender, ItemClickEventArgs e)
        {
            panelControl1.Controls.Clear();
            ucPhongkham frm = new ucPhongkham();
            frm.Dock = System.Windows.Forms.DockStyle.Fill;
            panelControl1.Controls.Add(frm);
        }// end btnPhongkham_ItemClick

        //them giao dien don vi tiep nhan
        private void btnDonvitiepnhan_ItemClick(object sender, ItemClickEventArgs e)
        {
            panelControl1.Controls.Clear();
            ucDonvitiepnhan frm = new ucDonvitiepnhan();
            frm.Dock = System.Windows.Forms.DockStyle.Fill;
            panelControl1.Controls.Add(frm);
        }// end btnDonvitiepnhan_ItemClick

        //logout tai khoan
        private void bbtnLogout_ItemClick(object sender, ItemClickEventArgs e)
        {
            DialogResult reusult = MessageBox.Show("Bạn có chắc chắn muốn thoát khỏi chương trình?"
                , "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (reusult == DialogResult.Yes)
            {
                bClosed = false;
                this.Visible = false;
                bClosed = true;
                FRM_Dangnhap frm = new FRM_Dangnhap();
                frm.Show();
            }// end if
        }// end bbtnLogout_ItemClick

        //them giao dien benh nhan
        private void btnBenhnhan_ItemClick(object sender, ItemClickEventArgs e)
        {
            panelControl1.Controls.Clear();
            ucDanhsachbenhnhan frm = new ucDanhsachbenhnhan();
            frm.Dock = System.Windows.Forms.DockStyle.Fill;
            panelControl1.Controls.Add(frm);
        }

        //giao dien thong ke danh sach
        private void btnThongkedanhsach_ItemClick(object sender, ItemClickEventArgs e)
        {
            panelControl1.Controls.Clear();
            ucThongketheodonvitiepnhan frm = new ucThongketheodonvitiepnhan();
            frm.Dock = System.Windows.Forms.DockStyle.Fill;
            panelControl1.Controls.Add(frm);
        }

        //giao dien nguoi dung
        private void btnNguoidung_ItemClick_1(object sender, ItemClickEventArgs e)
        {
            panelControl1.Controls.Clear();
            ucNguoidung frm = new ucNguoidung();
            frm.Dock = System.Windows.Forms.DockStyle.Fill;
            panelControl1.Controls.Add(frm);
        }

        //bao cao theo thoi gian
        private void btnTheothoigian_ItemClick(object sender, ItemClickEventArgs e)
        {
            panelControl1.Controls.Clear();
            ucThongkenangcao frm = new ucThongkenangcao();
            frm.Dock = System.Windows.Forms.DockStyle.Fill;
            panelControl1.Controls.Add(frm);
        }

        //bao cao theo nhan vien
        private void btnTheonhanvien_ItemClick(object sender, ItemClickEventArgs e)
        {
            panelControl1.Controls.Clear();
            ucThongketheonhanvien frm = new ucThongketheonhanvien();
            frm.Dock = System.Windows.Forms.DockStyle.Fill;
            panelControl1.Controls.Add(frm);
        }

        //bao cao so luong
        private void btnThongkesoluong_ItemClick(object sender, ItemClickEventArgs e)
        {
            panelControl1.Controls.Clear();
            ucThongkesoluong frm = new ucThongkesoluong();
            frm.Dock = System.Windows.Forms.DockStyle.Fill;
            panelControl1.Controls.Add(frm);
        }// end btnThongkesoluong_ItemClick

        private void btnDoimatkhau_ItemClick(object sender, ItemClickEventArgs e)
        {
            FRM_Doimatkhau frm = new FRM_Doimatkhau();
            frm.ShowDialog();
        }// end btnDoimatkhau_ItemClick

        private void bbtnDangnhap_ItemClick(object sender, ItemClickEventArgs e)
        {
            FRM_Dangnhap frm = new FRM_Dangnhap();
            frm.ShowDialog();
        }// end bbtnDangnhap_ItemClick

        private void FRM_Manhinhchinh_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }// end FRM_Manhinhchinh_FormClosing

        private void timer1_Tick(object sender, EventArgs e)
        {
            Timer.Caption = DateTime.Now.ToString("dd/MM/yy - hh:mm:ss");
        }//end timer1_Tick

        private void btnDiadiem_ItemClick_1(object sender, ItemClickEventArgs e)
        {
            panelControl1.Controls.Clear();
            ucDiadiem frm = new ucDiadiem();
            frm.Dock = System.Windows.Forms.DockStyle.Fill;
            panelControl1.Controls.Add(frm);
        }//end btnDiadiem_ItemClick_1

        private void FRM_Manhinhchinh_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (bClosed == false)
            {
                DialogResult dr = MessageBox.Show("Bạn có muốn thoát không ?", "Thông báo"
                    , MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dr == DialogResult.No) e.Cancel = true;
            }// end if
        }// end FRM_Manhinhchinh_FormClosing
    }// end class
}// end namespace